package com.kaka.daoimpl;

import com.kaka.dao.TeacherDao;
import com.kaka.javabean.Teacher;
import com.kaka.util.MyJDBCUtil;

import java.util.List;

public class TeacherDaoImpl implements TeacherDao {
    @Override
    public List<Teacher> selectByUsernameAndPassword(String username, String password) {
        String sql = "select * from teacher where username = ? and password = ?";
        return MyJDBCUtil.dqlSQL(Teacher.class, sql, username, password);
    }

    @Override
    public List<Teacher> selectAll() {
        String sql = "select * from teacher";
        return MyJDBCUtil.dqlSQL(Teacher.class, sql);
    }

    @Override
    public int updatePasswordByTid(int tid, String newPassword) {
        String sql = "update teacher set password = ? where tid = ?";
        return MyJDBCUtil.dmlSQL(sql, newPassword, tid);
    }

    @Override
    public int insertNewTeacher(Teacher teacher) {
        String sql = "insert into teacher(username, password, tname) values (?,?,?)";
        return MyJDBCUtil.dmlSQL(sql, teacher.getUsername(), teacher.getPassword(), teacher.getTname());
    }

    @Override
    public int deleteByTid(int tid) {
        String sql = "delete from teacher where tid = ?";
        return MyJDBCUtil.dmlSQL(sql,tid);
    }
}
